package com.moji.controller.api;


import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import com.moji.common.base.ApiResult;
import com.moji.common.entity.MyPage;
import com.moji.entity.MjUser;
import com.moji.entity.dto.AddMjUserDto;
import com.moji.entity.dto.ModifyPasswordDto;
import com.moji.entity.dto.QueryUserDto;
import com.moji.entity.vo.MjUserVo;
import com.moji.service.MjUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * <p>
 * 客户信息表 前端控制器
 * </p>
 *
 * @author ccl
 * @since 2024-08-17
 */
@RestController
@RequestMapping("api/mjUser")
@Api(tags = "客户相关api接口", value = "客户相关api接口")
public class MjUserController {

    @Resource
    private MjUserService mjUserService;

    @Resource
    private RedisTemplate redisTemplate;

    @PostMapping("add")
    @ApiOperation("保存 用户类型 userType 0 - 个人用户 1 - 企业用户\"")
    public ApiResult add(@RequestBody AddMjUserDto dto){
        return ApiResult.ok(mjUserService.add(dto));
    }

    @PostMapping("edit")
    @ApiOperation("修改 用户类型 userType 0 - 个人用户 1 - 企业用户\"")
    public ApiResult edit(@RequestBody AddMjUserDto dto){
        return ApiResult.ok(mjUserService.edit(dto));
    }

    @GetMapping("delete")
    @ApiOperation("删除")
    public ApiResult delete(Long id){
        return ApiResult.ok(mjUserService.delete(id));
    }

    @PostMapping("queryPage")
    @ApiOperation("分页查询")
    public ApiResult<MyPage<MjUser>> queryPage(@RequestBody QueryUserDto dto){
        MyPage<MjUser> ccpSystemUserMyPage = mjUserService.queryByPage(dto);
        return ApiResult.ok(ccpSystemUserMyPage);
    }

    @GetMapping("detail")
    @ApiOperation(value = "详情",response = MjUserVo.class)
    public ApiResult detail(@RequestParam("id") Long id){
        return ApiResult.ok(mjUserService.detail(id));
    }


    @PostMapping("modifyPassword")
    @ApiOperation("忘记密码")
    public ApiResult modifyPassword(@RequestBody ModifyPasswordDto modifyPasswordDao){
        return ApiResult.ok(mjUserService.modifyPassword(modifyPasswordDao));
    }

    @GetMapping("resetPassword")
    @ApiOperation(value = "重置密码",response =Boolean.class)
    public ApiResult reset(Long id){
        return ApiResult.ok(mjUserService.resetPassword(id));
    }

}

